#ifndef BULLET_PHYSICS_H
#define BULLET_PHYSICS_H

#include <btBulletDynamicsCommon.h>
#include <vector>
#include "Singleton.h"
#include "Vec3.h"

namespace Engine
{
	class BulletPhysics : public NonCopyable
	{
	private:
		btDynamicsWorld* m_dynamicWorld;
		btCollisionConfiguration* m_collConfig;
		btDispatcher* m_dispatcher;
		btBroadphaseInterface* m_broadPhase;
		btConstraintSolver* m_constraintSolver;

		btRigidBody* m_plane;
		std::vector<btRigidBody*> bodies;

		BulletPhysics();
		friend class Singleton<BulletPhysics>;

	public:
		//debug only
		float red;
		btVector3 p;
		btVector3 rayFrom;
		btVector3  rayTo;

		Vec3 GetP()
		{
			Vec3 thisP = Vec3(p.getX(), 0.0f, p.getZ());

			return thisP;
		}

		//static bool callbackFunc(btManifoldPoint& cp,const btCollisionObject* obj1,int id1,int index1,const btCollisionObject* obj2,int id2,int index2);
		void Initialize();
		void Update(const Vec3& m, const Vec3& f);
		void Draw();
		void Shutdown();

		btRigidBody* CreatePlane(const Vec3& pos);
		void RenderPlane(btRigidBody* body);
	};

	typedef Singleton<BulletPhysics> TheBtPhysics;
}

#endif